package com.haixiaoke.saas.manage.lock.controller;

import javax.servlet.http.HttpServletResponse;

import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.lock.domain.LockQrCode;
import com.haixiaoke.saas.lock.service.ILockQrCodeService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 设备二维码Controller
 *
 * @author panda
 * @date 2025-05-15
 */
@RestController
@RequestMapping("/manage/lock/qrCode")
public class ManageLockQrCodeController extends BaseController {
    @Autowired
    private ILockQrCodeService lockQrCodeService;

    /**
     * 查询设备二维码列表
     */
    @GetMapping("/page")
    public TableDataInfo list(LockQrCode lockQrCode) {
        startPage();
        List<LockQrCode> list = lockQrCodeService.selectLockQrCodeList(lockQrCode);
        return getDataTable(list);
    }

    /**
     * 新增设备二维码
     */
    @PostMapping
    public AjaxResult add(@RequestBody LockQrCode lockQrCode) {
        lockQrCode.setCreateBy(getUsername());
        return toAjax(lockQrCodeService.insertLockQrCode(lockQrCode));
    }

    /**
     * 删除设备二维码
     */
    @DeleteMapping("/{qrCodeId}")
    public AjaxResult remove(@PathVariable Long qrCodeId) {
        return toAjax(lockQrCodeService.deleteLockQrCodeByQrCodeId(qrCodeId));
    }
}
